package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.DrawBookDetialModuleBookListData;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.rjwh.dingdong.client.widget.RoundImageView;

/**
 * @author Kay
 * @ClassName RadioAlbumListAdapter
 * @Description 听听专辑列表
 * @date 2016-10-26
 * @history 2016-10-26 author: description:
 */

public class DrawBookDetailModuleBookListAdapter extends AdapterBase<DrawBookDetialModuleBookListData> {

    private Context mContext;

    public DrawBookDetailModuleBookListAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    protected View getExView(int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.draw_book_detial_module_book_list_item, null);
        }

        RoundImageView drawBookDetialModuleBookListItemImg = ViewHolder.get(convertView, R.id.draw_book_detial_module_book_list_item_img);
        TextView drawBookDetialModuleBookListItemTitleTv = ViewHolder.get(convertView, R.id.draw_book_detial_module_book_list_item_title_tv);
        TextView drawBookDetialModuleBookListItemTypeTv = ViewHolder.get(convertView, R.id.draw_book_detial_module_book_list_item_type_tv);
        TextView drawBookDetialModuleBookListItemAgeTv = ViewHolder.get(convertView, R.id.draw_book_detial_module_book_list_item_age_tv);
        TextView drawBookDetialModuleBookListItemDiscTv = ViewHolder.get(convertView, R.id.draw_book_detial_module_book_list_item_disc_tv);

        DrawBookDetialModuleBookListData drawBookDetialModuleBookListData = getList().get(position);

        if (drawBookDetialModuleBookListData == null) {
            return convertView;
        }

        String coverurl = drawBookDetialModuleBookListData.getCoverurl();
        String bookname = drawBookDetialModuleBookListData.getBookname();
        String agestage = drawBookDetialModuleBookListData.getAgestage();
        String bookdescription = drawBookDetialModuleBookListData.getBookdescription();
        String typetitle = drawBookDetialModuleBookListData.getTypetitle();

        if (!AsStrUtils.isEmpty(bookname)) {
            drawBookDetialModuleBookListItemTitleTv.setText(bookname);
        }
        if (!AsStrUtils.isEmpty(bookdescription)) {
            drawBookDetialModuleBookListItemDiscTv.setText(bookdescription);
        }
        if (!AsStrUtils.isEmpty(typetitle)) {
            drawBookDetialModuleBookListItemTypeTv.setText(typetitle);
        }
        if (!AsStrUtils.isEmpty(agestage)) {
            drawBookDetialModuleBookListItemAgeTv.setText(agestage);
        }

        Glide.with(mContext).load(coverurl).dontAnimate().placeholder(R.drawable.icon_pic_holder).error(R.drawable.icon_pic_holder)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(drawBookDetialModuleBookListItemImg);

        return convertView;
    }
}
